package com.example.smartcity.ui.person.login

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.example.smartcity.databinding.ActivityOrderFormBinding
import com.example.smartcity.ui.person.fragment.PersonFragment_1
import com.example.smartcity.ui.person.fragment.personFragment_2
import com.google.android.material.tabs.TabLayoutMediator

class OrderFormActivity : AppCompatActivity() {
    private lateinit var mBinding: ActivityOrderFormBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = ActivityOrderFormBinding.inflate(layoutInflater)
        setContentView(mBinding.root)
        title = "订单列表"

        // 显示回退按钮
        supportActionBar?.setDisplayHomeAsUpEnabled(true)

        // 设置TabLayout和viewpager2
        setTabViewPager()
    }

    private fun setTabViewPager() {

        // ViewPager2适配器
        mBinding.viewpager2.adapter = object : FragmentStateAdapter(this){

            override fun getItemCount() = 2

            override fun createFragment(position: Int): Fragment = when(position){
                0 -> PersonFragment_1()
                else -> personFragment_2()
            }
        }

        TabLayoutMediator(mBinding.tablayout, mBinding.viewpager2){ tab, position ->
            when(position){
                0 -> tab.text = "已支付"
                else -> tab.text = "未支付"
            }
        }.attach()

    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        this.finish()
        return super.onOptionsItemSelected(item)
    }
}